/*!
 * @file VertexBuffer.cpp
 * @author naoki takeda
 * @version 1.0
 */
#include "StdAfx.h"
#include <d3d11.h>
#include "src/VertexBufferImpl.h"
#include "src/ManagerImpl.h"

namespace NTEngine {
namespace Graphics {

#if ( USE_GRAPHICS_API == GRAPHICS_API_D3D9 )
const UINT VertexBuffer::Impl::Stride[] = {
	sizeof( BaseStreamSource ),
	sizeof( NormalStreamSource ),
	sizeof( BlendingStreamSource ),
};
VertexBuffer VertexBuffer::create( int vertexNumber, int format ) {
	VertexBuffer instance;
	instance.m_Impl = NEW Impl( vertexNumber, format, g_ManagerImpl->device(), 0 );
	return instance;
}
#elif ( USE_GRAPHICS_API == GRAPHICS_API_D3D11 )
VertexBuffer VertexBuffer::create( int vertexNumber, int format ) {
	VertexBuffer instance;
	instance.m_Impl = NEW Impl( vertexNumber, format, g_ManagerImpl->device(), g_ManagerImpl->deviceContext() );
	return instance;
}
#endif

template<> void VertexBuffer::lock( BaseStreamSource** pp ) {
	ASSERT( m_Impl && "Graphics::VertexBuffer : This is empty object." );
//	*pp = static_cast< BaseStreamSource* >( m_Impl->lock( 0 ) );
}

template<> void VertexBuffer::lock( NormalStreamSource** pp ) {
	ASSERT( m_Impl && "Graphics::VertexBuffer : This is empty object." );
//	*pp = static_cast< NormalStreamSource* >( m_Impl->lock( 1 ) );
}

template<> void VertexBuffer::lock( BlendingStreamSource** pp ) {
	ASSERT( m_Impl && "Graphics::VertexBuffer : This is empty object." );
//	*pp = static_cast< BlendingStreamSource* >( m_Impl->lock( 2 ) );
}

template<> void VertexBuffer::unlock( BaseStreamSource** pp ) {
	ASSERT( *pp && "Graphics::VertexBuffer : give LOCKED pointer." );
	ASSERT( m_Impl && "Graphics::VertexBuffer : This is empty object." );
//	m_Impl->unlock( 0 );
	*pp = 0;
}

template<> void VertexBuffer::unlock( NormalStreamSource** pp ) {
	ASSERT( *pp && "Graphics::VertexBuffer : give LOCKED pointer." );
	ASSERT( m_Impl && "Graphics::VertexBuffer : This is empty object." );
//	m_Impl->unlock( 1 );
	*pp = 0;
}

template<> void VertexBuffer::unlock( BlendingStreamSource** pp ) {
	ASSERT( *pp && "Graphics::VertexBuffer : give LOCKED pointer." );
	ASSERT( m_Impl && "Graphics::VertexBuffer : This is empty object." );
//	m_Impl->unlock( 2 );
	*pp = 0;
}

int VertexBuffer::vertexNumber() const {
	return m_Impl->vertexNumber();
}

VertexBuffer::VertexBuffer( const Impl* )
: m_Impl( NULL ) {
}

#define TYPE VertexBuffer
#include "NTEngine/Base/Impl/ReferenceTypeTemplate.h"

} // namespace Graphics
} // namespace NTEngine
// EOF